package com.example.okhttptest;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;


import com.alibaba.fastjson.JSON;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        Log.e("TestActivity - >","onCreate");
        findViewById(R.id.test).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                test02();
            }
        });
        findViewById(R.id.event).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                test03();
////                startActivity(new Intent(TestActivity.this,EventActivity.class));
//                Ha h = new Ha();
//                h.setRoleId(9);
//                h.setRoleName("ha");
//                h.setStatus("suc");
//                Log.e("TestActivity JSON - >",JSON.toJSON(h).toString());

                startActivity(new Intent(TestActivity.this,StickActivity.class));
            }
        });
    }

    private void test() {
        Map<String,Object> map = new HashMap<>();
        map.put("ha",1);
        map.put("kid",65);
        map.put("haaa",12);
        map.put("kiddfs",652);
        map.put("hadf",13);
        map.put("kidu",625);
        List<Object> list = new ArrayList<>();
        list.add(map);
        list.add(map);
//        JSONArray
//        list.add(map);
//        list.add(map);
//        list.add(map);
//        Log.e("TestActivity",JSON.parse(list.toString()).toString());
//        JSONArray jsonArray = new JSONArray();
//        JsonReader jsonReader = new JsonReader();
//        JSON.parse(list.toString());
    }

    private void test02(){
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("ha1",1);
            jsonObject.put("ha2",1);
            jsonObject.put("ha3",1);
            jsonObject.put("ha4",1);
             Log.e("TestActivity",jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    private void test03(){
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("ha1",1);
            jsonObject.put("ha2",1);
            jsonObject.put("ha3",1);
            jsonObject.put("ha4",1);
             Log.e("TestActivity",jsonObject.toString());
             JSONArray jsonArray = new JSONArray();
             jsonArray.put(jsonObject);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.e("TestActivity - >","onResume");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.e("TestActivity - >","onRestart");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.e("TestActivity - >","onStop");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.e("TestActivity - >","onPause");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.e("TestActivity - >","onDestroy");
    }
}
